package com.xzc._2_deploy;

import org.kie.api.KieServices;
import org.kie.api.builder.KieScanner;
import org.kie.api.builder.ReleaseId;
import org.kie.api.runtime.KieContainer;

/**
 * 使用Kie Scanner来自动扫描新版本的规则，自动加载，加载的策略在drool6书里面有详解
 */
public class KieScannerDeployer {

    /**
     * 在Kie Container上注册Kie Scanner
     * 只有在Container中创建的KieBase才会自动更新，直接newKieBase()不会
     * MAVEN的版本可以设置
     */
    public void registerScannerOnContainer() {
        KieServices kieServices = KieServices.Factory.get();
        ReleaseId releaseId = kieServices.newReleaseId("org.acme", "myartifact", "1.0-SNAPSHOT");
        KieContainer kContainer = kieServices.newKieContainer(releaseId);
        KieScanner kScanner = kieServices.newKieScanner(kContainer);

        // Start the KieScanner polling the Maven repository every 10 seconds
        kScanner.start(10000L);
    }
}
